package com.game.utils
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class LoadStrData
	{
		
		private var _load:URLLoader
		
		private var _sFun:Function;
		private var _eFun:Function;
	
		
		/**
		 * 读取外部文本
		 * @param url文本路径
		 * @param sFun(str:String) 读取成功
		 * @param eFun() 读取失败
		 * */
		public function LoadStrData(url:String,sFun:Function,eFun:Function=null)
		{
			_sFun=sFun;
			_eFun=eFun;
			_load=new URLLoader();
			_load.load(new URLRequest(url));
			_load.addEventListener(Event.COMPLETE,comFun);
			_load.addEventListener(IOErrorEvent.IO_ERROR,errorFun);
			
		}
		private function comFun(e:Event):void{
			_sFun(e.target.data)
			gc();
		}
		private function errorFun():void{
			if(_eFun!=null){
				_eFun();
			}
			
			gc();
		}
		private function gc():void{
			_load.removeEventListener(Event.COMPLETE,comFun);
			_load.removeEventListener(IOErrorEvent.IO_ERROR,errorFun);
			_load=null;
			_sFun=null;
			_eFun=null;
	
		}
		
		
	}
}